#
# Makefile, Makefile.in
# Makefiles for the Utilities of the Protea Project
# Copyright (C) 2008 Bruce A. James
#
# This file is part of the Protea Project.
#
# The Protea Project is free software; you can redistribute it and/or modify it 
# under the terms of the GNU General Public License as published by the 
# Free Software Foundation, either version 3 of the License, or (at your 
# option) any later version.
#
# The Protea Project is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
# for more details.
# 
# You should have received a copy of the GNU General Public License along 
# with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Please send correspondence to:
#
# theproteaproject@gmail.com
#

PROGRAMS = makehfile prep srm appdicextract loadappdic clearapp unload reload appdicupgrade
#uesl.so
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @INTERNAL_FLAG@ -I$(XERCESCROOT)/include
COMPILE = $(CXX) $(CXXFLAGS)

LINK = $(COMPILE)
XML=-L $(XERCESCROOT)/lib/ -lxerces-c -L $(XALANCROOT)/lib/ -lxalan-c -lxalanMsg
LIBS = @LIBS@ -L.. -lprotea$(TOOLSBASE)

DIRS = customizer sai
INSTALL = /@INSTALL@

SRCS := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
DEPS := $(patsubst %.cpp,%.d,$(SRCS))

all : $(PROGRAMS) dirs

install:
#	@echo Extracting appdic data
#	@export LD_LIBRARY_PATH=$(XSIROOT)/Lib
#	@./ae 1
#	@./ae 2
#	@./ae 3

	@$(INSTALL) -d $(XSIROOT)/appdic
	@$(INSTALL) extract.* $(XSIROOT)/appdic

	@$(INSTALL) -d $(XSIROOT)/Tools
	@$(INSTALL) $(PROGRAMS) $(XSIROOT)/Tools
	@for dir in $(DIRS); do set -e; $(MAKE) -C $$dir install ; done

dirs:
	@for dir in $(DIRS); do set -e; $(MAKE) -C $$dir ; done

clean :
	-rm $(PROGRAMS) $(OBJS) $(DEPS)
	@for dir in $(DIRS); do set -e; $(MAKE) -C $$dir clean ; done

depend: $(DEPS)
	@for dir in $(DIRS); do set -e; $(MAKE) -C $$dir depends ; done

%.d: %.cpp
	@echo "Creating dependency file: $*.d"
	@set -e; g++ -MM -I$(XERCESCROOT)/include $< \
	| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
	[ -s $@ ] || rm -f $@

%.o: %.cpp
	@echo "Compiling source file: $*.cpp"
	@set -e; $(COMPILE) -o $@ -c $<



uesl.so : uetest.cpp
	$(CXX) @LDSHFLAGS@ @PICFLAG@ -o $@ $^

prep : prep.o
	@echo "Linking prep"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $^

makehfile : makehfile.o components_helper.o
	@echo "Linking makehfile"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $^

srm : srm.o
	@echo "Linking srm"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $<

appdicextract : AppdicExtract.o components_helper.o
	@echo "Linking appdicextract"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $^

loadappdic : LoadAppdic.o
	@echo "Linking loadappdic"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $<

clearapp : ClearApp.o
	@echo "Linking clearapp"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $<

unload : unload.o
	@echo "Linking unload"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $<

reload : reload.o
	@echo "Linking reload"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $<

appdicupgrade : AppdicUpgrade.o
	@echo "Linking appdicupgrade"
	@set -e; $(LINK) -o $@ $(XML) $(LIBS) $<

#%: %.cpp
#	$(CXX) -o $@ $(LIBS) $<


-include $(DEPS)
